import {useModel} from 'umi'
import React from 'react'
import {setCookie} from '@/utils/cookie'

type pageProp = {children?: React.ReactNode; permissionID?: string}
const permissions = ({children, permissionID}: pageProp) => {
	const {initialState, setInitialState} = useModel('@@initialState')
	const {permission} = initialState || {}
	return (
		<a
			href=" "
			onClick={(e) => {
				setCookie('permissionID', permissionID, 7)
				setInitialState({
					...initialState,
					permissionID,
				})
				e.preventDefault()
			}}>
			{permission?.indexOf(permissionID) === -1 ||
			permission?.indexOf(permissionID) === undefined ? (
				''
			) : (
				<>{children}</>
			)}
		</a>
	)
}

export default permissions
